package com.fulihui.wgj.admin.integration.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.fulihui.common.builder.web.JsonResultBuilder;
import com.fulihui.common.conv.BeanConv;
import com.fulihui.common.result.web.Result;
import com.fulihui.common.util.RpcResultCheckUtil;
import com.fulihui.wgj.admin.api.miniapp.vo.MiniAppBasicVO;
import com.fulihui.wgj.admin.integration.MiniAppBasicServiceClient;
import com.fulihui.wgj.facade.dto.MiniProgramBasicDTO;
import com.fulihui.wgj.facade.result.miniapp.MiniProgramBasicResult;
import com.fulihui.wgj.facade.service.miniapp.MiniAppBasicService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Levon
 * @date: 2018-07-26 13:59
 */
@Service
public class MiniAppBasicServiceClientImpl implements MiniAppBasicServiceClient {

    @Reference(version = "1.0.0")
    private MiniAppBasicService miniAppBasicService;

    @Override
    public Result<List<MiniAppBasicVO>> queryMiniAppAll() {
        MiniProgramBasicResult result = miniAppBasicService.queryMiniProgramList();
        if (RpcResultCheckUtil.isSuccess(result)) {
            List<MiniProgramBasicDTO> values = result.getValues();
            return JsonResultBuilder.succ(BeanConv.copy(values, MiniAppBasicVO.class));
        }
        return JsonResultBuilder.fail(result.getErrcode(), result.getErrmsg());
    }
}
